<?php

namespace mpend\modules\home\models;

use Yii;
use common\helpers\Url;

/**
 * This is the model class for table "{{%cms_channel}}".
 *
 * @property int $id
 * @property string $name 频道名称
 * @property string|null $description 频道描述
 * @property string|null $icon 图标
 * @property string|null $bgcolor 背景色
 * @property string|null $link 跳转链接
 * @property int $listorder 排序
 * @property int $status 状态
 * @property int $created_at
 * @property int $updated_at
 * @property int $deleted_at
 */
class MenuChannel extends \common\models\cms\CmsChannel {

    public $pagesize = false;
    public $limitSize = 4;

    /**
     * @inheritdoc
     */
    public function buildQuery($alias = 't') {
        $query = static::find()->active(static::STATUS_ACTIVE)->orderBy([
            'listorder' => SORT_ASC
        ]);
        return $query;
    }

    /**
     * @inheritdoc
     */
    public function fields() {
        return [
            'id',
            'name',
            'description',
            'bgcolor',
            'thumb' => function() {
                return Url::attach($this->icon);
            },
        ];
    }

}
